package com.qf.common;

import java.io.IOException;
import java.util.Properties;

public class MyFactory {
    private Properties pp = new Properties();
    public MyFactory(){}
    public MyFactory(String config){
        try {
            pp.load(MyFactory.class.getResourceAsStream(config));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public Object getBean(String baenName){
        try {
            String property = pp.getProperty(baenName);
            if (property!=null){
                Class cc = null;
                cc = Class.forName(property);
                //获取方法的实例
                return cc.newInstance();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }
}

